package org.pzy.java.concurrency;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author pzy
 * for循环嵌入线程池
 */
@Slf4j
public class ForExecutorDemo {

    public static void main(String[] args) {
        ScheduledExecutorService exec = Executors.newScheduledThreadPool(4);
        List<Integer> asList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
        for (int i = 0; i < asList.size(); i++) {
            Integer integer = asList.get(i);
            exec.schedule(() -> log.info("{}", integer), i, TimeUnit.SECONDS);
        }
    }
}
